
<template>
<div>

  <a-select
      ref="select"
      v-model:value="lostType"
      style="width: 120px"
      @focus="focus"
      @change="handleChange"
  >
    <a-select-option value="">全部</a-select-option>
    <a-select-option value="招领">招领</a-select-option>
    <a-select-option value="寻物" >寻物</a-select-option>
  </a-select>

  <a-table :columns="columns" :data-source="data">



    <span slot="action" slot-scope="text, record">
      <a-popconfirm
          title="您要删除当前帖子?"
          ok-text="Yes"
          cancel-text="No"
          @confirm="deleteLost(record.lostId)"
          @cancel="()=>{}"
      >
    <a>删除帖子</a>
  </a-popconfirm>

    </span>

  </a-table>

</div>

</template>

<script>
import { message } from 'ant-design-vue';
const columns = [
  {
    title: '标题',
    dataIndex: 'title',
    key: 'title',
  },
  {
    title: '内容',
    dataIndex: 'text',
    key: 'text',
  },
  {
    title: '发布者',
    dataIndex: 'creatUserName',
    key: 'creatUserName',
  },
  {
    title: '发布时间',
    key: 'createTime',
    dataIndex: 'createTime',
  },
  {
    title: '发布类型',
    key: 'lostType',
    dataIndex: 'lostType',
  },
  {
    title: '操作',
    key: 'action',
    scopedSlots: { customRender: 'action' },
  },
];




/**
 * 这是物品管理
 */
export default ({
  data() {
    return {
      data:[],
      columns,
      lostType:"全部",
    }
  },
  beforeCreate() {

    this.$http({
      method: 'post',
      url: 'http://localhost:18082/loatandfound/list',
      data: {
        typeValue:this.lostType
      },
      headers:{
        user:localStorage.getItem("user"),
      }
    }).then((e)=>{

      if(e.data.status){

        this.data=e.data.data;


      }

    })


  },
  mounted() {

  },
  methods: {
    deleteLost(e){

      this.$http({
        method: 'delete',
        url: 'http://localhost:18082/loatandfound/delete',
        data: {
          lostId:e
        },
        headers:{
          user:localStorage.getItem("user"),
        }
      }).then((e)=>{

        if(e.data.status==true){
          message.info("删除成功！",3);
          this.$http({
            method: 'post',
            url: 'http://localhost:18082/loatandfound/list',
            data: {
              typeValue:this.lostType
            },
            headers:{
              user:localStorage.getItem("user"),
            }
          }).then((e)=>{

            if(e.data.status){

              this.data=e.data.data;


            }

          })


        }else{
          message.error("删除失败！",3);
        }


      })


    },
    focus(){},
    handleChange(){

      this.$http({
        method: 'post',
        url: 'http://localhost:18082/loatandfound/list',
        data: {
          text:"",
          title:"",
          dateS:[],
          tagS:[],
          typeValue:this.lostType
        },
        headers:{
          user:localStorage.getItem("user"),
        }
      }).then((e)=>{

        if(e.data.status){

          this.data=e.data.data;


        }

      })

    }
  },
})

</script>

